package 作业5.Microblogging;

public class User {
    //用户名
    private String userName;
    //用户密码
    private String pwd;
    //生日
    private String birthday;
    //手机号
    private String telNumber;
    //邮箱
    private String email;

    //扩展属性:确认密码
    private String rePwd;
    //有参构造函数
    public User(String userName,String pwd,String date,String telNumber,String email)
    {
        setUserName(userName);
        setPwd(pwd);
        setBirthday(date);
        setTelNumber(telNumber);
        setEmail(email);
    }
    //无参构造函数
    public User() {

    }
    //属性访问器
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public String getBirthday() {
        return birthday;
    }
    public void setBirthday(String str) {
        this.birthday = str;
    }
    public String getTelNumber() {
        return telNumber;
    }
    public void setTelNumber(String telNumber) {
        this.telNumber = telNumber;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getRePwd() {
        return rePwd;
    }
    public void setRePwd(String rePwd) {
        this.rePwd = rePwd;
    }
    //重写toString()方法进行用户信息输出
    public String toString(){
        return "用户信息:\r姓名:"+getUserName()+"\r生日:"
                +getBirthday()+"\r邮箱:"+getEmail()+"\r手机号:"+getTelNumber()+"\r用户密码:"+getPwd();
    }
    //重写hashCode方法
    public int hashCode(){
        return userName.hashCode();
    }
    //重写equals方法
    public boolean equals(Object obj) {
        //判断是否是同一个对象
        if (this==obj) {
            return true;
        }
        //判断对象是否为空，为空直接返回false，判断对象是否是User对象
        if (obj==null||getClass()!=obj.getClass()) {
            return false;
        }
        //将对象强制转换为User对象
        User other=(User)obj;
        //判断用户名是否为空
        if (userName==null) {
            if (other.userName!=null) {
                return false;
            }
        }else  if (!userName.equals(other.userName)) {
            return false;
        }

        return true;
    }

}

